package whf.shop.service;

import java.util.List;

import whf.framework.exception.FindException;
import whf.framework.exception.NotFoundException;
import whf.framework.exception.ServiceNotFoundException;
import whf.framework.file.IFile;
import whf.framework.file.IFolder;
import whf.framework.util.BeanFactory;
import whf.shop.dao.ProductDAO;
import whf.shop.entity.Product;

/**
 * 服务对象具体实现，委托相应的dao对象实现相关操作
 * 
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2007-01-11
 */
public class ProductServiceImp extends whf.framework.service.ServiceImp<Product>
		implements ProductService {

	private ProductDAO productDAO;

	public void setProductDAO(ProductDAO productDAO) {
		this.productDAO = productDAO;
	}

	public static ProductService getProductService()
			throws ServiceNotFoundException {
		return (ProductService) BeanFactory.getService(ProductServiceImp.class);
	}

	/* (non-Javadoc)
	 * @see whf.framework.file.IFileService#loadByFolder(whf.framework.file.IFolder)
	 */
	public List<IFile> loadByFolder(IFolder folder) throws FindException {
		return null;
	}

	/* (non-Javadoc)
	 * @see whf.framework.file.IFileService#loadFile(long)
	 */
	public IFile loadFile(long fileId) throws NotFoundException {
		return this.findByPrimaryKey(fileId);
	}


	/* (non-Javadoc)
	 * @see whf.framework.file.IFileService#findByFileName(java.lang.String)
	 */
	public IFile findByFileName(String filename) throws FindException {
		List<Product> files = this.productDAO.find("t.phycialPath=?", filename);
		if(files.size() > 0){
			return (IFile)files.get(0);
		} else {
			return null;
		}
	}
}